﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArchivingDataModel
{
    public partial class Attachment
    {
        public string getImageUrl()
        {
            if (this.MimeType!=null &&( this.MimeType.ToLower() == "image/jpeg" || this.MimeType.ToLower() == "image/gif" || this.MimeType.ToLower() == "image/png" || this.MimeType.ToLower() == "image/jpg"))
            {
                return this.Attachment_Path;
            }
            else
            {
                return "~/images/unknown.png";
            }
        }
        public static string getImageUrl(object attachmentID)
        {
            if (attachmentID != null && attachmentID!=DBNull.Value)
            {
                long id = Convert.ToInt64(attachmentID);
                using (ArchivingDataEntities ent = new ArchivingDataEntities())
                {
                    return ent.Attachments.FirstOrDefault(i => i.Attachment_ID == id).getImageUrl();
                }
            }
            else
            {
                return "";
            }
        }
    }
}
